using System;
using System.Collections.Generic;
using UnityEngine;

namespace PKGames
{
	public class PluginAndroid : PluginNative
	{
		private AndroidJavaClass _pluginClass;

		public PluginAndroid(string javaPackageName, string javaClassName)
		{
			_pluginClass = new AndroidJavaClass(javaPackageName + "." + javaClassName);
		}

		protected void CallAsyncStaticMethod(string methodName, Action<string> successAction, Action<string> errorAction, params object[] args)
		{
			string callbackObjectName = CreateCallbackObject(methodName, successAction, errorAction);
			object[] args2 = PrependCallbackInfo(callbackObjectName, args);
			_pluginClass.CallStatic(methodName, args2);
		}

		private object[] PrependCallbackInfo(string callbackObjectName, object[] args)
		{
			List<object> list = new List<object>(args);
			list.Insert(0, "OnError");
			list.Insert(0, "OnSuccess");
			list.Insert(0, callbackObjectName);
			return list.ToArray();
		}

		protected void CallStaticMethod(string methodName, params object[] args)
		{
			_pluginClass.CallStatic(methodName, args);
		}

		protected T CallStaticMethod<T>(string methodName, params object[] args)
		{
			return _pluginClass.CallStatic<T>(methodName, args);
		}

		protected void CallStaticMethod(string methodName, string eventName, Dictionary<string, string> parameters, int eventRevision)
		{
			using (AndroidJavaObject androidJavaObject = new AndroidJavaObject("java.util.HashMap"))
			{
				IntPtr methodID = AndroidJNIHelper.GetMethodID(androidJavaObject.GetRawClass(), "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
				object[] array = new object[2];
				foreach (KeyValuePair<string, string> parameter in parameters)
				{
					using (AndroidJavaObject androidJavaObject2 = new AndroidJavaObject("java.lang.String", parameter.Key))
					{
						using (AndroidJavaObject androidJavaObject3 = new AndroidJavaObject("java.lang.String", parameter.Value))
						{
							array[0] = androidJavaObject2;
							array[1] = androidJavaObject3;
							AndroidJNI.CallObjectMethod(androidJavaObject.GetRawObject(), methodID, AndroidJNIHelper.CreateJNIArgArray(array));
						}
					}
				}
				//_pluginClass.CallStatic(methodName, eventName, androidJavaObject, eventRevision);
			}
		}
	}
}
